package com.goushu.mapper;

import com.goushu.pojo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface CustomerMapper {

    @Select("select * from customer where username=#{username}")
    Customer findByUserName(String username);

    void register(Customer customer);

    @Update("update customer set password=#{md5String}, update_time=now() where id=#{id}")
    void updatePwd(String md5String, Integer id);

    @Update("update customer set user_pic=#{avatarUrl}, update_time=now() where id=#{id}")
    void updateAvatar(String avatarUrl, Integer id);

    @Update("update customer set nickname=#{nickname}, email=#{email}, phone=#{phone}, address=#{address},update_time=#{updateTime} where id=#{id}")
    void update(Customer customer);

//    @Insert("insert into bookStore.order (b_id, c_id, count, create_time, name, phone, address, state) values (#{book.bid}, #{cid}, #{book.count}, now(), #{data.name}, #{data.phone}, #{data.address}, 1)")
    void order(Orders orders);

    @Select("select orders_detail.id, phone, name, address, create_time, b_id, count, state from orders join orders_detail on orders.id = o_id where c_id=#{id};")
    List<OrderQuery> listOrder(Integer id);

    @Insert("insert into book_comment (b_id, c_id, detail, create_time) values (#{addComment.id}, #{cId}, #{addComment.detail}, #{addComment.createTime});")
    void addComment(AddComment addComment, Integer cId);

    @Update("update orders_detail set state=4 where id=#{id}")
    void modifyOrder(Integer id);

    void orderDetail(List<OrdersDetail> ordersDetails);

    @Update("update book set sales = sales + #{count}, stock = stock - #{count} where id = #{bId}")
    void saleOfBook(Integer bId, Integer count);
}
